package study.spring.mail.mimehelper;

import java.io.File;

import javax.mail.internet.MimeMessage;

import org.springframework.core.io.FileSystemResource;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;

import study.spring.mail.OrderManager;

public class MimeMessageOrder implements OrderManager {

	private String host;
	private String path;

	@Override
	public void sendMail() {

		try {
			JavaMailSenderImpl sender = new JavaMailSenderImpl();
			sender.setHost(host);
			MimeMessage message = sender.createMimeMessage();
			MimeMessageHelper helper = new MimeMessageHelper(message);
			helper.setTo("fenshen6046@163.com");
			helper.setText("Dear yaoming,thank you for placing order. your order number is 1");
			if (path != null) {
				FileSystemResource file = new FileSystemResource(new File(path));
				helper.addAttachment("Coolimage", file);
			}

			sender.send(message);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public String getHost() {
		return host;
	}

	public void setHost(String host) {
		this.host = host;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

}
